﻿<%@ Page Title="" Language="C#" MasterPageFile="~/WebsiteSub.master" AutoEventWireup="true" CodeBehind="Opret.aspx.cs" Inherits="TireService.Website.Integration.Opret" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxHiddenField" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">

    <!-- Javascript -->
    <script language="javascript" type="text/javascript">

        function OnSelectedTireSetActionChanged() {
            // Show/hide picup options
            pPickUpTires.SetVisible(ddlOtherTireSet.GetValue().toString() == 1)
        }

        function OnPickUpCustomerTireSetSelectedAddressChanged(s, e) {
            var SelectedPickUpCustomerTireSetAddress = ddlSelectAddress.GetValue();
            var PickUpCustomerTireSetAddress = ddlSelectAddress.GetText();
            PickUpCustomerTireSetAddress = PickUpCustomerTireSetAddress.split("|");

            if (SelectedPickUpCustomerTireSetAddress == 0) {
                // Primary address has been selected
                txtPickUpCustomerTireSetAddress.SetText(PickUpCustomerTireSetAddress[0]);
                txtPickUpCustomerTireSetZipCode.SetText(PickUpCustomerTireSetAddress[1]);
                txtPickUpCustomerTireSetCity.SetText(PickUpCustomerTireSetAddress[2]);
            }
            if (SelectedPickUpCustomerTireSetAddress == 1) {
                // Secondary address has been selected
                txtPickUpCustomerTireSetAddress.SetText(PickUpCustomerTireSetAddress[0]);
                txtPickUpCustomerTireSetZipCode.SetText(PickUpCustomerTireSetAddress[1]);
                txtPickUpCustomerTireSetCity.SetText(PickUpCustomerTireSetAddress[2]);
            }
            if (SelectedPickUpCustomerTireSetAddress == 2) {
                // Custom address has been selected
                txtPickUpCustomerTireSetAddress.SetText("");
                txtPickUpCustomerTireSetZipCode.SetText("");
                txtPickUpCustomerTireSetCity.SetText("");
                txtPickUpCustomerTireSetAddress.SetFocus();
            }
        }

        function AddCar() {
            // Validate car values
            txtRegistrationNumber.Validate();
            ddlCarBrand.Validate();
            txtModel.Validate();
            txtEngineSize.Validate();
            ddlFuelType.Validate();
            txtYear.Validate();
            txtColor.Validate();
            rblCurrentTireSet.Validate();
            ddlOtherTireSet.Validate();

            var isFormValid = ASPxClientEdit.ValidateGroup("Step3");
            if (isFormValid) {

                var isForm2Valid = true;

                if (ddlOtherTireSet.GetValue().toString() == 1) {
                    // Do validation related to pickup customer tireset
                    txtPickUpCustomerTireSetAddress.Validate();
                    txtPickUpCustomerTireSetZipCode.Validate();
                    txtPickUpCustomerTireSetCity.Validate();

                    isForm2Valid = ASPxClientEdit.ValidateGroup("PickUpTires");
                }

                if (isForm2Valid) {
                    // 0: Registrationnumber
                    // 1: Car brand id
                    // 2: Car model
                    // 3: Enginesize
                    // 4: Fueltype
                    // 5: Year
                    // 6: Color
                    // 7: Currenttireset (0: Winter, 1: Summer)
                    // 8: Locking bolts on current tireset (true/false)
                    // 9: Othertireset (0: Get on first service, 1: Pick-up, 2: MBH has customer tires)
                    // 10: Locking bolts on other tireset (true/false)
                    // 11: Pickup address (optional)
                    // 12: Pickup zipcode (optional)
                    // 13: Pickup city (optional)
                    // 14: Remarks to pickup address (optional)
                    // 15: SubscriptionId
                    // 16: CustomerSubscriptionId

                    var values = txtRegistrationNumber.GetText();
                    values += '|' + ddlCarBrand.GetValue();
                    values += '|' + txtModel.GetText();
                    values += '|' + txtEngineSize.GetText();
                    values += '|' + ddlFuelType.GetValue();
                    values += '|' + txtYear.GetValue();
                    values += '|' + txtColor.GetText();
                    values += '|' + rblCurrentTireSet.GetValue();
                    values += '|' + cbLockingBolt.GetChecked();
                    values += '|' + ddlOtherTireSet.GetValue();
                    values += '|' + cbLockingOtherTireSet.GetChecked();
                    values += '|' + txtPickUpCustomerTireSetAddress.GetText();
                    values += '|' + txtPickUpCustomerTireSetZipCode.GetText();
                    values += '|' + txtPickUpCustomerTireSetCity.GetText();
                    values += '|' + txtPickUpCustomerTireSetRemarkToAddress.GetText();
                    values += '|' + lblSubscriptionId.GetText();
                    values += '|' + hfCustomerSubscriptionId.Get("CustomerSubscriptionId"); 

                    // Postback values to server for saving
                    callBackAddCar.PerformCallback(values);
                }
            }
        }

        function OnCallBackAddCarComplete(s, e) {
//            // Call function on orderingpage - input result (car number that was saved)
//            OrderingPageCallBack(e.result);

        }

        function CallBackAddCarError(s, e) {
            alert('Fejl opstod: ' + e.message);
        }

    </script>

    <%--<dx:ASPxCallback ID="callBackAddCar" ClientInstanceName="callBackAddCar"
        runat="server" OnCallback="callBackAddCar_Callback">
        <ClientSideEvents CallbackError="CallBackAddCarError" CallbackComplete="OnCallBackAddCarComplete" />
    </dx:ASPxCallback>--%>

    <dx:ASPxCallbackPanel ID="callBackAddCar" ClientInstanceName="callBackAddCar" runat="server" Width="100%" OnCallback="callBackAddCar_Callback" RenderMode="Table">
        <ClientSideEvents CallbackError="CallBackAddCarError" EndCallback="OnCallBackAddCarComplete" />
        <PanelCollection>
            <dx:PanelContent>            

                <h2>Indtastning af biloplysninger</h2>
                <dx:ASPxLabel ID="lblCarToAdd" runat="server" Text="" ClientIDMode="AutoID" >
                </dx:ASPxLabel> 

                <table border="0" cellspacing="0" cellpadding="5" width="550px">
                    <tr>
                        <td>
                            <b>
                                <dx:ASPxLabel ID="lblCarData" runat="server" Text="Bildata:">
                                </dx:ASPxLabel>                    
                            </b>
                        </td>
                        <td>
                            <dx:ASPxLabel ID="lblCarCount" runat="server" Text="">
                            </dx:ASPxLabel>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <p class="mediumtext">
                                <dx:ASPxLabel ID="lblSubscriptionDescription" runat="server" Text="Abonnement" ClientIDMode="AutoID" >
                                </dx:ASPxLabel>
                                <dx:ASPxLabel ID="lblSubscriptionId" ClientInstanceName="lblSubscriptionId" runat="server" ClientIDMode="AutoID" ClientVisible="false" >
                                </dx:ASPxLabel>                        
                            </p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblRegistrationNumber" runat="server" Text="Registreringsnr. (*)">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtRegistrationNumber" ClientInstanceName="txtRegistrationNumber" runat="server" Width="90px" NullText="Ex. RX23523" ClientIDMode="AutoID" ToolTip="Indtast din bils registrerings nummer (Nummerplade - ex. XR34535)">
                                <ValidationSettings ValidationGroup="Step3" RequiredField-IsRequired="true" RequiredField-ErrorText="Udfyld registreringsnummer (Nummerplade)" RegularExpression-ValidationExpression="[a-zA-Z0-9]{7}" RegularExpression-ErrorText="Registrerings nr. ikke gyldigt - skal være i format AG12345" ErrorDisplayMode="ImageWithTooltip" />
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblCarBrandId" runat="server" Text="Bilmærke (*)">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxComboBox ID="ddlCarBrand" ClientInstanceName="ddlCarBrand" runat="server" IncrementalFilteringMode="StartsWith" Width="175px" ClientIDMode="AutoID" ToolTip="Vælg/indtast din bil's bilmærke - eksempel Toyota"
                                EnableIncrementalFiltering="True" Spacing="0" ValueType="System.String">
                                <LoadingPanelStyle ImageSpacing="5px">
                                </LoadingPanelStyle>
                                <ValidationSettings ErrorDisplayMode="ImageWithTooltip" ValidationGroup="Step3" RequiredField-IsRequired="true" RequiredField-ErrorText="Udfyld bilmærke">
                                    <RequiredField ErrorText="Udfyld bilmærke" IsRequired="True" />
                                </ValidationSettings>
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblModel" runat="server" Text="Model">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtModel" ClientInstanceName="txtModel" MaxLength="15" runat="server" Width="175px" NullText="Ex. Yaris, Corolla" ClientIDMode="AutoID" ToolTip="Indtast din bils model - eksempel Yaris">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblEngineSize" runat="server" Text="Motor">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtEngineSize" ClientInstanceName="txtEngineSize" MaxLength="10" runat="server" Width="175px" ClientIDMode="AutoID" NullText="Ex. 1.0, 1.2, 2.0" ToolTip="Indtast din bils motor størrelse - 1.0, 1.2, 2.0 osv.">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblFuelType" runat="server" Text="Brændstof (*)">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxComboBox ID="ddlFuelType" ClientInstanceName="ddlFuelType" runat="server" IncrementalFilteringMode="StartsWith" EnableIncrementalFiltering="True" Width="100px" ClientIDMode="AutoID" Spacing="0" ValueType="System.String" ToolTip="Vælg brændstof type for din bil">
                                <ValidationSettings ErrorDisplayMode="ImageWithTooltip" ValidationGroup="Step3" RequiredField-IsRequired="true" RequiredField-ErrorText="Vælg brændstoftype for bil"></ValidationSettings>
                                <Items>
                                    <dx:ListEditItem Value="0" Text="Benzin" />
                                    <dx:ListEditItem Value="1" Text="Diesel" />
                                </Items>
                                <LoadingPanelStyle ImageSpacing="5px">
                                </LoadingPanelStyle>
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblColor" runat="server" Text="Farve (*)">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtColor" ClientInstanceName="txtColor" runat="server" MaxLength="15" Width="175px" ClientIDMode="AutoID" ToolTip="Indtast farven på din bil">
                                <ValidationSettings ErrorDisplayMode="ImageWithTooltip" ValidationGroup="Step3" RequiredField-IsRequired="true" RequiredField-ErrorText="Udfyld farve på bil"></ValidationSettings>
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblYear" runat="server" Text="Årgang (*)">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxComboBox ID="txtYear" ClientInstanceName="txtYear" runat="server" Width="100px" ClientIDMode="AutoID" Spacing="0" ValueType="System.String" IncrementalFilteringMode="StartsWith" EnableIncrementalFiltering="True" ToolTip="Indtast/vælg din bils årgang">
                                <LoadingPanelStyle ImageSpacing="5px">
                                </LoadingPanelStyle>
                                <ValidationSettings ErrorDisplayMode="ImageWithTooltip" ValidationGroup="Step3" RequiredField-IsRequired="true" RequiredField-ErrorText="Udfyld årgang">
                                    <RequiredField ErrorText="Udfyld årgang" IsRequired="True" />
                                </ValidationSettings>
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblCurrentTireSet" runat="server" Text="Bilen køre lige nu med (*)">
                            </dx:ASPxLabel>
                        </td>
                        <td colspan="2">
                            <dx:ASPxRadioButtonList ID="rblCurrentTireSet" ClientInstanceName="rblCurrentTireSet" runat="server" Width="250px">
                                <Items>
                                    <dx:ListEditItem Value="0" Text="Vinterhjul" />
                                    <dx:ListEditItem Value="1" Text="Sommerhjul" />
                                </Items>
                                <ValidationSettings ErrorDisplayMode="ImageWithTooltip" ValidationGroup="Step3" RequiredField-IsRequired="true" RequiredField-ErrorText="Venligst angiv hvilke hjul der sidder på bilen nu"></ValidationSettings>
                            </dx:ASPxRadioButtonList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblLockingBolt" runat="server" Text="Låsebolte">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxCheckBox ID="cbLockingBolt" ClientInstanceName="cbLockingBolt" runat="server" ToolTip="Sæt kryds hvis din bil har låsebolte på dine hjul - dvs. der kræves en special nøgle for at afmontere dine hjul">
                            </dx:ASPxCheckBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblOtherTireSet" runat="server" Text="Håndtering øvrigt hjulsæt">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxComboBox ID="ddlOtherTireSet" ClientInstanceName="ddlOtherTireSet" runat="server" Width="200px">
                                <Items>
                                    <dx:ListEditItem Value="0" Text="Jeg medbringer selv hjulene ved 1. skift" Selected="true" />
                                    <dx:ListEditItem Value="1" Text="Hjulene skal afhentes på anden adresse - pris 250 DKK" />
                                    <%--<dx:ListEditItem Value="2" Text="Mobilhjulskift.dk har hjulene" />--%>
                                </Items>
                                <ClientSideEvents SelectedIndexChanged="function(s, e) { OnSelectedTireSetActionChanged(); }" />
                                <ValidationSettings CausesValidation="true" ValidationGroup="Step3" RequiredField-IsRequired="true" RequiredField-ErrorText="Vælg håndtering af øvrigt hjulsæt" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                    <RequiredField IsRequired="True" ErrorText="V&#230;lg håndtering af øvrigt hjuls&#230;t"></RequiredField>
                                </ValidationSettings>
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxLabel ID="lblLockingBoltsOtherTireSet" runat="server" Text="Låsebolte til øvrigt hjulsæt">
                            </dx:ASPxLabel>
                        </td>
                        <td>
                            <dx:ASPxCheckBox ID="cbLockingOtherTireSet" ClientInstanceName="cbLockingOtherTireSet" runat="server">
                            </dx:ASPxCheckBox>
                        </td>
                    </tr>
                </table>
                <dx:ASPxPanel ID="pPickUpTires" ClientInstanceName="pPickUpTires" runat="server" ClientVisible="false">
                    <PanelCollection>
                        <dx:PanelContent>
                            <table border="0" cellspacing="0" cellpadding="5" width="550px">
                                <tr>
                                    <td>
                                        <dx:ASPxLabel ID="lblPickUpTireSetPrice" runat="server" Text="Pris i DKK">
                                        </dx:ASPxLabel>
                                    </td>
                                    <td>
                                        250,-
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <dx:ASPxLabel ID="lblPickUpAddress" runat="server" Text="Vælg adresse">
                                        </dx:ASPxLabel>
                                    </td>
                                    <td>
                                        <dx:ASPxComboBox ID="ddlSelectAddress" ClientInstanceName="ddlSelectAddress" IncrementalFilteringMode="StartsWith" DropDownStyle="DropDownList" runat="server">
                                            <ClientSideEvents SelectedIndexChanged="function(s, e) { OnPickUpCustomerTireSetSelectedAddressChanged(s); }" />
                                            <ValidationSettings CausesValidation="true" ValidationGroup="PickUpTires" RequiredField-IsRequired="true" RequiredField-ErrorText="Vælg adresse" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                <RequiredField IsRequired="True" ErrorText="V&#230;lg adresse"></RequiredField>
                                            </ValidationSettings>
                                        </dx:ASPxComboBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <dx:ASPxTextBox ID="txtPickUpCustomerTireSetAddress" ClientInstanceName="txtPickUpCustomerTireSetAddress" NullText="Adresse" runat="server" Width="250px">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="PickUpTires" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast adresse" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                <RequiredField IsRequired="True" ErrorText="Indtast adresse"></RequiredField>
                                            </ValidationSettings>
                                        </dx:ASPxTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <dx:ASPxTextBox ID="txtPickUpCustomerTireSetZipCode" ClientInstanceName="txtPickUpCustomerTireSetZipCode" NullText="Postnr" runat="server" Width="50px">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="PickUpTires" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast postnr" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                <RequiredField IsRequired="True" ErrorText="Indtast postnr"></RequiredField>
                                            </ValidationSettings>
                                        </dx:ASPxTextBox>
                                    </td>
                                    <td>
                                        <dx:ASPxTextBox ID="txtPickUpCustomerTireSetCity" ClientInstanceName="txtPickUpCustomerTireSetCity" NullText="By" runat="server" Width="170px">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="PickUpTires" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast by" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                <RequiredField IsRequired="True" ErrorText="Indtast by"></RequiredField>
                                            </ValidationSettings>
                                        </dx:ASPxTextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <dx:ASPxTextBox ID="txtPickUpCustomerTireSetRemarkToAddress" ClientInstanceName="txtPickUpCustomerTireSetRemarkToAddress" NullText="Bemærkning til adressen" runat="server" Width="250px">
                                        </dx:ASPxTextBox>
                                    </td>
                                </tr>
                            </table> 
                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxPanel>
                <table border="0" cellspacing="0" cellpadding="5" width="550px">
                    <tr>
                        <td colspan="2">
                            <dx:ASPxButton ID="btnAddCar" ClientInstanceName="btnAddCar" runat="server" Text="Videre" AutoPostBack="False" UseSubmitBehavior="False">
                                <ClientSideEvents Click="function(s, e) { AddCar(); }" />
                            </dx:ASPxButton>
                        </td>
                    </tr>
                </table>

                <!-- Hidden field used indicating customersubscription for car -->
                <dx:ASPxHiddenField ID="hfCustomerSubscriptionId" ClientInstanceName="hfCustomerSubscriptionId" runat="server">
                </dx:ASPxHiddenField>

            </dx:PanelContent>
        </PanelCollection>
    </dx:ASPxCallbackPanel>

</asp:Content>
